package com.uzhie.web.controller.http;

import com.alibaba.fastjson.JSONObject;
import com.uzhie.web.anno.Auth;
import com.uzhie.web.bean.PageBean;
import com.uzhie.web.bean.PayloadBean;
import com.uzhie.web.controller.http.comm.CommController;
import com.uzhie.web.module.ReportFlow;
import com.uzhie.web.service.ReportFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Zhangdequan on 2018/7/18.
 */
@RestController
@RequestMapping(value = "reportFlow")
public class ReportFlowController extends CommController {

    @Autowired
    private ReportFlowService reportFlowService;

    /**
     * 查询返回所有的目录数据(树状结构)
     *
     * @param body
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    @Auth
    @RequestMapping(value = "list")
    public PayloadBean selectAllCatalogToTree(@RequestBody(required = false) JSONObject body, @RequestBody(required = false) PageBean page) {

        List<ReportFlow> list = null;
        String departId = body.getString("departId");
        String vehicleNumber = body.getString("vehicleNumber");
        String beginTime = body.getString("beginTime");
        String endTime = body.getString("endTime");
        try {
            list = reportFlowService.selectReportFlow(departId, vehicleNumber, beginTime, endTime, page);
            return buildResponseWithPage(list, page);
        } catch (IllegalArgumentException e) {
            return buildResponseWithPage(null, page, e.getMessage());
        }
    }

}
